package com.liu;

import freemarker.template.Configuration;
import freemarker.template.Template;
import java.io.File;
import java.io.FileWriter;
import java.util.HashMap;
import java.util.Map;

/**
 * chance！Time
 * @author liuqian
 * @date 2022-06-25 16:11
 * *
 */
public class FreemarkerDemo {
    public static void main(String[] args) throws Exception{
        //1,创建配置类
        Configuration configuration = new Configuration(Configuration.getVersion());
        //2,设置模板所在的目录
        configuration.setDirectoryForTemplateLoading(new File("D:\\200_study\\ftl"));
        //设置字符集
        configuration.setDefaultEncoding("utf-8");
        //4，添加模板
        Template template = configuration.getTemplate("test.ftl");
        //5,创建数据模型
        Map map = new HashMap<>();
        map.put("name", "张三");
        map.put("message", "欢迎来快乐星球！");
        //6，创建输出文件路径对象
        FileWriter out = new FileWriter(new File("d:\\test.html"));

        template.process(map,out);
        out.close();
    }
}
